using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Ent.Web;
using Ent.Web.Helper;
using Ent.Web.WebControl;
using Ent.Web.WebControl.Parameters;
using Ent.Voice.Show;
public partial class Controls_Event_SetSponsor : Ent.Web.WebControl.UserControl
{
    private Settings _pop;
    int minSpAmt = 1;
    int maxSpAmt = 99999;
    string voteStartDate = "";
    string evEndDate = "";
    string nomStartDate = "";
    bool allowNom = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        evEndDate = (Values[EventProperty.DueDate] != null ? Values[EventProperty.DueDate].ToString() : Event.MaxDate.ToShortDateString());
        Dictionary<string, string> rep = new Dictionary<string, string>();

        rvSponcerStData.MaximumValue = (evEndDate == Event.MinDate.ToShortDateString() ? Event.MaxDate.ToShortDateString() : evEndDate);
        rvSponcerStData.MinimumValue = DateTime.Today.ToShortDateString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvSponcerStData.MinimumValue);
        rep.Add("$2", rvSponcerStData.MaximumValue);
        rep.Add("$3", "Sponsor Start");
        rvSponcerStData.ErrorMessage = ResourceHelper.Get("MSG_RVDueDate", rep);

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Sponsor Start Date");
        rfvSponcerStData.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        rep = new Dictionary<string, string>();
        rep.Add("$1", "Minimum Sponsor Amount");
        rfvMinSponsor.ErrorMessage = ResourceHelper.Get("MSG_RFVRequired", rep);

        rvMinSponsor.MaximumValue = maxSpAmt.ToString();
        rvMinSponsor.MinimumValue = minSpAmt.ToString();
        rep = new Dictionary<string, string>();
        rep.Add("$1", rvMinSponsor.MinimumValue);
        rep.Add("$2", rvMinSponsor.MaximumValue);
        rep.Add("$3", "Minimum Sponsor Amount");
        rvMinSponsor.ErrorMessage = ResourceHelper.Get("MSG_RVMaxCount", rep);

        if (txtSponcerStData.Text == "")
            txtSponcerStData.Text = DateTime.Today.ToShortDateString();

        if (allowNom)
        {
            lblNomStart.Text = "Nom. Starts On:";
            valNomStart.Text = nomStartDate;
        }
        lblEventStart.Text = "Event Starts On:";
        lblEventEnd.Text = "Event Ends On:";
        lblVoteStart.Text = "Voting Starts On:";
        valVoteStart.Text = voteStartDate;
        valEventStart.Text = DateTime.Today.ToShortDateString();
        valEventEnd.Text = evEndDate;

        btnShowCal.Attributes.Add("onclick", "show_cal(400, 160, this, '" + txtSponcerStData.ClientID + "');");

        PopuplateControls();
    }
    public override void AddJavascript()
    {
        try
        {
            LoadJavascript("Javascripts/Settings.js");
            LoadJavascript("Javascripts/calendar.js");
            divJavascript.InnerHtml += JavascriptText;
        }
        catch (Exception exc)
        { }
    }
    public void PopuplateControls()
    {
        _pop = new Settings(Server.MapPath("Data/Settings.xml"));
        ddlCurrency.Items.AddRange(_pop.GetItemCollection("Currency"));
    }
    public override void SetEvents()
    {
        if (cbSponcership.Checked)
        {
            OnLoadEnable("tabSponsorship");
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvSponcerStData.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + rfvSponcerStData.ClientID + "'),true)",
                "_ValidatorEnable(document.getElementById('" + rfvMinSponsor.ClientID + "'),true)" ,
                "_ValidatorEnable(document.getElementById('" + rvMinSponsor.ClientID + "'),true)" 
            });
        }
        else
        {
            OnLoadDisable("tabSponsorship");
            OnLoadExecute(new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvSponcerStData.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + rfvSponcerStData.ClientID + "'),false)",
                "_ValidatorEnable(document.getElementById('" + rfvMinSponsor.ClientID + "'),false)" ,
                "_ValidatorEnable(document.getElementById('" + rvMinSponsor.ClientID + "'),false)" 
            });
        }
        
        SetOnClickEvent(new OnclickParam(cbSponcership, null, "tabSponsorship", 
            new string[] { 
                "_ValidatorEnable(document.getElementById('" + rvSponcerStData.ClientID + "'),!document.getElementById('" + txtSponcerStData.ClientID + "').disabled)" ,
                "_ValidatorEnable(document.getElementById('" + rfvSponcerStData.ClientID + "'),!document.getElementById('" + txtSponcerStData.ClientID + "').disabled)",
                "_ValidatorEnable(document.getElementById('" + rfvMinSponsor.ClientID + "'),!document.getElementById('" + txtMinSponsor.ClientID + "').disabled)" ,
                "_ValidatorEnable(document.getElementById('" + rvMinSponsor.ClientID + "'),!document.getElementById('" + txtMinSponsor.ClientID + "').disabled)" 
                },
            null));
    }
    public override void Init()
    {
        foreach (string key in Values.Keys)
        {
            if (Values[key] == null)
                continue;
            switch (key)
            {
                
                case EventProperty.Sponcership:
                    cbSponcership.Checked = Convert.ToBoolean(Values[key]);
                    break;
                case EventProperty.SponcerStData:
                    txtSponcerStData.Text = (string)Values[key];
                    break;
                case EventProperty.MinSponsor:
                    txtMinSponsor.Text = (string)Values[key];
                    break;
                case EventProperty.SCurrency:
                    ddlCurrency.SelectedIndex = ddlCurrency.Items.IndexOf(ddlCurrency.Items.FindByValue(Values[key].ToString()));
                    break;
                default:
                    if (key.Contains(EventProperty.NCurrency))
                    {
                        ddlCurrency.SelectedIndex = ddlCurrency.Items.IndexOf(ddlCurrency.Items.FindByValue(Values[key].ToString()));
                        ddlCurrency.Enabled = false;
                    }
                    if (key.Contains(EventProperty.VoteStDate))
                        voteStartDate = (string)Values[key];
                    if(key.Contains(EventProperty.DueDate))
                        evEndDate = (string)Values[key];
                    if(key.Contains(EventProperty.ParticipationStDate))
                        nomStartDate = (string)Values[key];
                    if(key.Contains(EventProperty.Participation))
                        allowNom = MathFunction.ConvertToBoolean(Values[key]);
                    break;
            }
        }
    }
    public override void Dispose()
    {
        //throw new Exception("The method or operation is not implemented.");
    }
    public override Dictionary<string, object> GetValues()
    {
        Dictionary<string, object> retValue = new Dictionary<string, object>();
        
        retValue.Add(EventProperty.Sponcership, cbSponcership.Checked);
        retValue.Add(EventProperty.SponcerStData, txtSponcerStData.Text);
        retValue.Add(EventProperty.MinSponsor, txtMinSponsor.Text);
        retValue.Add(EventProperty.SCurrency, ddlCurrency.SelectedValue);
        
        return retValue;
    }
}
